package com.arron.ssm.service.impl;

import com.arron.ssm.dao.EmployeeMapper;
import com.arron.ssm.entity.Employee;
import com.arron.ssm.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Classname EmployeeServiceImpl
 * @Date 2020/9/23 18:13
 * @Created by 刘
 */
@Service
public class EmployeeServiceImpl implements EmployeeService {

    @Autowired
    EmployeeMapper employeeMapper;

    @Override
    public Employee queryEmpById(Long id) {
        return employeeMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<Employee> queryAllEmp() {
        List<Employee> employees = employeeMapper.selectList();
        return employees;
    }


    @Override
    public Integer addEmp(Employee employee) {
        int insert = employeeMapper.insert(employee);
        return insert;
    }

    @Override
    public Integer removeById(Long id) {
        int i = employeeMapper.deleteByPrimaryKey(id);
        return i;
    }

    @Override
    public Integer updateById(Employee employee, Long id) {
        //先按照id查出员工
        Employee employee1 = employeeMapper.selectByPrimaryKey(id);
        int i = employeeMapper.updateByPrimaryKeySelective(employee, id, employee1.getVersion());
        return i;
    }
}
